
clear
clear matrix

#delimit cr
use ALLNSFG24feb14.dta
 
 *Create the teen pregnancy sample, just want people whose first conception 
 *was before the age of 18, and of those people just want those who conceive for the first
 *time before 1969.

drop if agefirstconception>=1800
drop if date1concept>=1969

gen weeks_preg = .
replace weeks_preg = WKS_PREG if survey==1995
replace weeks_preg = 4.3*MON_PREG if WKS_PREG==0 & survey==1995
replace weeks_preg = 1.5*4.3 if DK3GEST==1 & survey==1995

replace weeks_preg = B_15 if survey==1988
replace weeks_preg = 1.5*4.3 if B_16==1 & survey==1988

replace weeks_preg = B47*4.3 if survey==1982 & (OUTCOME == 3|OUTCOME==4)
replace weeks_preg = . if (B47==97|B47==98|B47==99) & (OUTCOME == 3|OUTCOME==4) & survey==1982
replace weeks_preg = B39 if survey == 1982 & OUTCOME==2
replace weeks_preg = . if (B39==97|B39==98|B39==99) & (OUTCOME == 2) & survey==1982
replace weeks_preg = 9*4.3 if survey==1982 & OUTCOME==1
replace weeks_preg = 1.5*4.3 if B48==1 & survey==1982
replace weeks_preg = 1.5*4.3 if B40==1 & survey==1982

replace weeks_preg = 9*4.3 if (PREG1_OUTCOME==3|PREG1_OUTCOME==4) & survey==1973
replace weeks_preg = PREG1_NUMMMP*4.3 if (PREG1_OUTCOME==5|PREG1_OUTCOME==6) & survey==1973

replace weeks_preg = 9*4.3 if (BPREC4==1|BPREC4==3) & survey==1976
replace weeks_preg = monthspreg*4.3 if monthspreg~=. & survey==1976

replace weeks_preg = . if (weeks_preg == 97|weeks_preg==98|weeks_preg==99)

*Allow second trimester miscarriages to be counted
gen weeks_pregdk=weeks_preg
replace weeks_pregdk = 4.5*4.3 if B48==2 & survey==1982
replace weeks_pregdk = 4.5*4.3 if B_16==2 & survey==1988
replace weeks_pregdk = 4.5*4.3 if DK3GEST==2 & survey==1995
replace weeks_pregdk = 4.5*4.3 if DK1GEST==2 & survey==1995

gen weeks_preground = round(weeks_preg)
gen weeks_pregdkround = round(weeks_pregdk)

*Need to fix that if survey is 1995, and stillbirth, should be 4 not 3, and miscarriage should be
*3 not 4.
*Besides that OUTCOME is the same in every survey--1 for live birth, 2 for abortion, 3 for misc, 4 for
*still birth, 5 for current (except in 1995 5 is ectopic and 6 is current
*Outcome is never missing.

replace OUTCOME = 8 if survey==1995 & OUTCOME==4
replace OUTCOME = 9 if survey==1995 & OUTCOME==3

replace OUTCOME = 3 if OUTCOME==8
replace OUTCOME = 4 if OUTCOME==9

replace OUTCOME=1 if survey==1973 & (PREG1_OUTCOME==3|PREG1_OUTCOME==4)
replace OUTCOME=3 if survey==1973 & (PREG1_OUTCOME==5|PREG1_OUTCOME==6)

replace OUTCOME=1 if survey==1976 & (BPREC4==1|BPREC4==3)
replace OUTCOME=2 if survey==1976 & BPREC6==3
replace OUTCOME=3 if survey==1976 & BPREC6==2
replace OUTCOME=4 if survey==1976 & BPREC6==1

*Now, generate variables for whether birth, abortion, or miscarriage

gen birth = (OUTCOME==1)
gen abort = (OUTCOME==2)
gen miscdk = (OUTCOME==3 & weeks_pregdkround<=22)
replace miscdk = 1 if OUTCOME==4 & weeks_pregdkround<=22

*If they say they have a miscarriage or stillbirth, and we don't know the number of weeks
*pregnant they are, then set misc equal to missing.

replace miscdk = . if (OUTCOME==3|OUTCOME==4) & weeks_pregdkround==.

*For 1973, since data is not in long form don't need pregnum--just always use
*the specific variable for the first pregnancy
gen pregnum = BPREC if survey==1982
replace pregnum = PREG_NUM if survey==1988
replace pregnum = PREGORDR if survey==1995
replace pregnum = pregnum1976 if survey==1976

save teenpreg24feb14pre1969.dta, replace

*Make a new completed years of schooling variable, because they have different topcodes
*Note that EDUCAT is not missing in any of the surveys and is otherwise coded the same

gen educ = EDUCAT
replace educ = 18 if educ==19 & survey==1995

replace educ = ED_HIGRADE if survey==1973 & ED_COMPLETHI==1
replace educ = ED_HIGRADE - 1 if survey==1973 & ED_COMPLETHI==2

replace educ = SCHOOL if survey==1976
replace educ = . if SCHOOL == 99 & survey==1976

*Make a new mother education variable, because top codes are different
	*Note that in the 1973 survey there is no information on mother's education
gen momeduc = EDUCMOM
replace momeduc=18 if momeduc==19 & survey==1995
replace momeduc = . if momeduc==95

gen hasmomeduc = momeduc~=.

rename momeduc momeducwithmiss

gen momeduc = momeducwithmiss if hasmomeduc==1
replace momeduc = 0 if hasmomeduc==0

*Generate indicator for workingmother non-missing and then a new variable with zero's where missing.
	*Note that in 1973 survey no information on whether the respondent's mother
	*was working when the respondent was growing up.
gen hasworkingmother = workingmother~=.
rename workingmother workingmotherwithmiss

gen workingmother = workingmotherwithmiss if hasworkingmother==1
replace workingmother = 0 if hasworkingmother==0

gen lnfamincome = log(familyincome)

gen x = FMAR1AGE/100 if (survey==1988|survey==1982)
*Note that round here because the data for 1995 are rounded.
gen agefirstmarriage = round(x)
replace agefirstmarriage = FMAR1AGE if survey==1995

*Assume 16 -17 means 16 to under 18, and 18 to 19 means 18 to under 20
*Don't give age at first marriage in single years, so
*take the midpoint of the ranges.

replace agefirstmarriage = 15 if MAR_AGE1STM==1 & survey==1973
replace agefirstmarriage = 17 if MAR_AGE1STM==2 & survey==1973
replace agefirstmarriage = 19 if MAR_AGE1STM==3 & survey==1973
replace agefirstmarriage = 21 if MAR_AGE1STM==4 & survey==1973
replace agefirstmarriage = 23.5 if MAR_AGE1STM==5 & survey==1973
replace agefirstmarriage = 27.5 if MAR_AGE1STM==6 & survey==1973
replace agefirstmarriage = 32.5 if MAR_AGE1STM==7 & survey==1973
replace agefirstmarriage = . if MAR_AGE1STM==8 & survey==1973

*In 1976, agefirstmarriage is missing for some observations,
*including those who are married at some point.  1976 is the only
*year in which agefirstmarriage missing for someone who was married
*at some point.

replace agefirstmarriage = MARIAG if survey==1976
replace agefirstmarriage = . if MARIAG == 99 & survey==1976

gen educatl12 = educ>=12
replace educatl12 = . if educ==.

save, replace

save teenpreg24feb14smallpre1969.dta, replace
#delimit ;
keep  CASEID survey black white married divsep hispanic 
protestant catholic working childreneverborn
 agefirstconception ID_NUM merge1995interval agelt15 
 weeks_preg weeks_preground birth abort educ momeduc  
  lnfamincome date1concept totalobs totalwt wtuse wtcheck 
  workingmother 
  familyincome merge1982interval
 AGE PARITY agefirstmarriage LIVING14
 educatl12 FMARNO FMARITAL
 pregnum weeks_pregdkround miscdk hasworkingmother hasmomeduc momeducwithmiss 
 workingmotherwithmiss nevermarried OUTCOME DK3GEST DK1GEST B_15 B_16 B48 weeks_pregdk DATE1CON DATCON01 WKS_PREG MON_PREG
 MARITAL RMARITAL F51A F36A FMAR1CON CON1FMAR MAR1CON1 CON1MAR1 PREGNUM MAR_TIMES MAR_B4 MAR_STAT
 PREG_NUMLIVEB1 PREG_LIVEMB CEBTOTAL F5 A11 RES_WPARENTS MAR1_MMYY MARIDT A7_CM respbirthdate 
DOB_MMYY B22A MAR1MO B14MO FMAR1MO PREGEND MARDAT01 MAR_MMMYY cmmissingmonth PREG1_DTENDED BPREC2 date1conceptcm
C12 PREG1_NUMMMP monthspreg child1inhh child2inhh child3inhh totchild1inhh totchild2inhh totchild3inhh totchildinhh
CHHE1 CHHE2 CHHE3 BOX11_1 BOX11_2 BOX11_3 LIVEHER1 LIVEHER2 POVERTY FAM_POVERTY FAM_POVERTYCOL LB1_DTLSTLIV LB1_CWHERE
B9_1 B351 B40_1 LIV1CHLD LIV1CHILD F70 F_93 TOTINC PREG1_OUTCOME BPREC4 BP1920A PREGTYPE PREGXEN1 PREGXEN2 PREGXEN3;
 
 #delimit cr
 
save, replace

**************************************************
***Now get no teen pregnancy sample
**************************************************

clear

use ALLNSFG24feb14.dta

*want people whose teen years were all before 1969, so 
drop if AGE<32 & survey==1982
drop if AGE<38 & survey==1988
drop if AGE<45 & survey==1995
drop if AGE<23 & survey==1973
drop if AGE<26 & survey==1976

*Don't want people who conceived as teens (before 18), or for whom we don't 
*know the age at which they conceived.

drop if (agefirstconception<1800|agefirstconception==.)


save NSFGnoteenpreg24feb14pre1969.dta, replace

#delimit ;
keep  CASEID survey black white married divsep hispanic 
protestant catholic working childreneverborn
 agefirstconception ID_NUM merge1995interval agelt15 
 EDUCMOM EDUCDAD OUTCOME EDUCAT familyincome 
 FMAR1AGE date1concept totalobs totalwt wtuse wtcheck workingmother 
 AGE PARITY LIVING14 
  FMARNO ED_HIGRADE ED_COMPLETHI RES_WPARENTS SCHOOL A11 CEBTOTAL MAR1_MMYY MARIDT
 A7_CM respbirthdate DOB_MMYY FMAR1CON CON1FMAR MAR1CON1 CON1MAR1
B22A MAR1MO B14MO FMAR1MO PREGEND MARDAT01 MAR_MMMYY cmmissingmonth PREG1_DTENDED BPREC2
date1conceptcm C12 PREG1_NUMMMP monthspreg 
child1inhh child2inhh child3inhh totchild1inhh totchild2inhh totchild3inhh totchildinhh
CHHE1 CHHE2 CHHE3 BOX11_1 BOX11_2 BOX11_3 LIVEHER1 LIVEHER2 POVERTY FAM_POVERTY FAM_POVERTYCOL
LB1_DTLSTLIV LB1_CWHERE B9_1 B351 B40_1 LIV1CHLD LIV1CHILD F70 F_93 TOTINC PREG1_OUTCOME BPREC4
BP1920A PREGTYPE PREGXEN1 PREGXEN2 PREGXEN3;
 
 #delimit cr
 save NSFGnoteenpreg24feb14smallpre1969.dta, replace
 
gen educ = EDUCAT
replace educ = 18 if educ==19 & survey==1995

*Note that in 1973--educ is missing for a few because ED_COMPLETHI is 
*missing for some observations
replace educ = ED_HIGRADE if survey==1973 & ED_COMPLETHI==1
replace educ = ED_HIGRADE - 1 if survey==1973 & ED_COMPLETHI==2

replace educ = SCHOOL if survey==1976
replace educ = . if SCHOOL == 99 & survey==1976

gen momeduc = EDUCMOM
replace momeduc=18 if momeduc==19 & survey==1995
replace momeduc = . if momeduc==95

gen hasmomeduc = momeduc~=.

rename momeduc momeducwithmiss

gen momeduc = momeducwithmiss if hasmomeduc==1
replace momeduc = 0 if hasmomeduc==0

*Generate indicator for workingmother non-missing and then new variable with zero's where missing.

gen hasworkingmother = workingmother~=.
rename workingmother workingmotherwithmiss

gen workingmother = workingmotherwithmiss if hasworkingmother==1
replace workingmother = 0 if hasworkingmother==0

gen teenpregearlypd = 1
replace teenpregearlypd = 0 if teenpregearlypd==1

save NSFGnoteenpreg24feb14smallpre1969.dta, replace

*************************************************************
*Now append this to the file with the teen pregnancies.
*There is no overlap since in the teen preg file we just have dates of conception
*before 1969, while here they are only after 1969.
*************************************************************

append using teenpreg24feb14smallpre1969.dta

gen liveboth14 = LIVING14==1
replace liveboth14 = . if LIVING14==.

*Question about living with both parents at 14 is answered by 
*everyone in 1973
replace liveboth14 = RES_WPARENTS==1 if survey==1973

*Note that in 1976 for some reason that question is not in the codebook, 
*can obtain the answer from the follow-up of why not living with both
*parents--that is missing if they were living with both parents.

replace liveboth14 = F5==. if survey==1976

*There is no liveboth14 variable for 1995, so just make it zero since control for survey

replace liveboth14=0 if survey==1995

egen tagID = tag(CASEID)

*generate dummy variables for survey
gen survey1982 = survey==1982
gen survey1988 = survey==1988
gen survey1973 = survey==1973
gen survey1976 = survey==1976

*Get predicted education
#delimit ;
local controled AGE hispanic black white protestant catholic
workingmother hasworkingmother momeduc hasmomeduc liveboth14 survey1973 survey1982 survey1988
survey1976;

#delimit cr

reg educ `controled' if teenpregearlypd==0 & tagID==1 [pw=wtuse], r 
predict educpredict2

save teenpreg24feb14withindexpre1969.dta, replace

*In 1973 birth and misc are only equal to one if they are associated with the first
*pregnancy, so there is no pregnum variable

gen firstpregbirthdk = 1 if birth==1 & pregnum==1
replace firstpregbirthdk = 1 if birth==1 & survey==1973

replace firstpregbirthdk = 0 if miscdk==1 & pregnum==1
replace firstpregbirthdk = 0 if miscdk==1 & survey==1973

replace firstpregbirthdk = . if miscdk==.

gen agefirstconceptionUSE = agefirstconception/100

gen numbermarriages = FMARNO
replace numbermarriages = 0 if FMARNO==.
replace numbermarriages = MAR_TIMES if survey==1973
#delimit ;
replace numbermarriages = 0 if MAR_B4==0 & survey==1973 & 
MAR_TIMES==.;
replace numbermarriages = 1 if MAR_B4==2 & survey==1973 & 
MAR_TIMES==.;

#delimit cr
replace numbermarriages = A11 if survey==1976
replace numbermarriages = . if A11==9 & survey==1976
replace numbermarriages = 0 if A11==. & survey==1976

*Determine if the respondent was married before the pregnancy outcome
*Subtract date of marriage from date of the outcome.  If this is <0
*then the outcome was first.

gen marrpreoutcome = .

*1973--note that month is never missing for marriage or outcome
*and MAR1_MMYY==0 if never married or in only marriage...so if married
*only once have to use MAR_MMMYY

#delimit ;
gen mardate1973 = MAR_MMMYY if numbermarriages==1 & 
(married==1|(married==0&MAR1_MMYY==0&MAR_MMMYY~=0)) & survey==1973;

replace mardate1973 = MAR1_MMYY if ((married==0 & MAR1_MMYY~=0)|(numbermarriages>=2))
& survey==1973;

#delimit ;
replace marrpreoutcome = PREG1_DTENDED-mardate1973>=0 if survey==1973;

gen monthsbetwmarroutcome = PREG1_DTENDED-mardate1973 if survey==1973;

#delimit cr

*1976--note that MARIDT is sometimes equal to 999, set to missing
*if that is the case.  Also MARIDT is equal to zero if not applicable--but
*all of the people for whom not applicable have nevermarried==1

*Note that BPREC2 has some missing months--from Century Month = 946-976.  Create
*a new variable that is equal to BPREC2 before 946, but between 946 and 976
*is equal to the cmmissingmonth variable that created in the master file.

gen cmoutcome = BPREC2 if BPREC2<=945 & survey==1976
replace cmoutcome = cmmissingmonth if BPREC2>=946 & BPREC2<=976 & survey==1976
replace cmoutcome = . if BPREC2==999

replace marrpreoutcome = cmoutcome-MARIDT>=0 if survey==1976
replace marrpreoutcome = . if MARIDT==999 & survey==1976

replace monthsbetwmarroutcome = cmoutcome-MARIDT if survey==1976
replace monthsbetwmarroutcome = . if MARIDT==999 & survey==1976

*1982--note that if the month is missing B22A is coded such that
*the first digit is 9, and the last three digits are the the century
*month associated with June in the year of the pregnancy outcome
*So make a new variable with the 9 taken off

*Note that if MAR1MO==. then nevermarried = 1.  MAR1MO is never missing for
*reasons that was refused, not ascertained, etc.

gen x82 = B22A if survey==1982
replace x82 = . if B22A<=9629 & survey==1982
replace x82 = . if (B22A==9797|B22A==9898|B22A==9999) & survey==1982
tostring x82, gen(x82str)
gen cmoutcome82str = substr(x82str,2,3)
destring cmoutcome82str, gen(cmoutcome82)
replace cmoutcome82 = B22A if B22A<=9629 & survey==1982

replace marrpreoutcome = cmoutcome82-MAR1MO>=0 if survey==1982
replace marrpreoutcome = . if (B22A==9797|B22A==9898|B22A==9999|B22A==.) & survey==1982

replace monthsbetwmarroutcome = cmoutcome82-MAR1MO if survey==1982
replace monthsbetwmarroutcome = . if (B22A==9797|B22A==9898|B22A==9999|B22A==.) & survey==1982

*1988--if month is missing in B14MO or FMAR1MO, coded so first digit is 9
*and the remaining are the century month associated with June in the year
*of the pregnancy outcome. Note that nevermarried = 1 if FMAR1MO==.

gen x88 = B14MO if survey==1988
replace x88 = . if B14MO<=90713 & survey==1988
tostring x88, gen(x88str)
gen cmoutcome88str = substr(x88str,2,4)
destring cmoutcome88str, gen(cmoutcome88)
replace cmoutcome88 = B14MO if B14MO<=90713 & survey==1988

gen y88 = FMAR1MO if survey==1988
replace y88 = . if FMAR1MO<=90725 & survey==1988
tostring y88, gen(y88str)
gen mar1dt88str = substr(y88str,2,4)
destring mar1dt88str, gen(mar1dt88)
replace mar1dt88 = FMAR1MO if FMAR1MO<=90725 & survey==1988

replace marrpreoutcome = cmoutcome88-mar1dt88>=0 if survey==1988
replace marrpreoutcome = . if B14MO==. & survey==1988

replace monthsbetwmarroutcome = cmoutcome88-mar1dt88 if survey==1988
replace monthsbetwmarroutcome = . if B14MO==. & survey==1988

*1995--note that for PREGEND, month never missing, and nevermarried=1 if
*MARDAT01==.

replace marrpreoutcome = PREGEND-MARDAT01>=0 if survey==1995
replace marrpreoutcome = . if (PREGEND==.|PREGEND==9998|PREGEND==9999) & survey==1995

replace monthsbetwmarroutcome = PREGEND-MARDAT01 if survey==1995
replace monthsbetwmarroutcome = . if (PREGEND==.|PREGEND==9998|PREGEND==9999) & survey==1995

*If nevermarried, then can't have been married before the outcome

replace marrpreoutcome = 0 if nevermarried==1

*Generate an indicator for pre-conception marriages-note that there is a variable for this in 
*the 76, 82, 88, 95 surveys, but not in 73
	*Note that if CON1FMAR==0, they married less than one month after conception--
*This is zero for 
	*1. Those who marry after conception
	*2. Those who never marry
	*3. Those who have the variable as missing, but also include an indicator so that don't have to drop them
		*Note that the variable is only missing for the non-abortion first pregnancy sample for 12
		*people in the 1982 survey
	
gen havemarrpreconcept = CON1FMAR~=999 if (survey==1982|survey==1988)
replace havemarrpreconcept = CON1MAR1~=. if survey==1995
	
gen marrpreconcept = (CON1FMAR==995) if (survey==1982|survey==1988)
replace marrpreconcept = . if (CON1FMAR==999|CON1FMAR==996)
replace marrpreconcept = 0 if CON1FMAR==999
replace marrpreconcept = CON1MAR1==995 if survey==1995
replace marrpreconcept = 0 if CON1MAR1==. & survey==1995

gen marrpreconceptdate = marrpreconcept
gen havemarrpreconceptdate = havemarrpreconcept

replace marrpreconceptdate = (date1conceptcm-MARIDT>=0) if survey==1976
replace marrpreconceptdate = . if MARIDT==999 & survey==1976
replace marrpreconceptdate = . if date1conceptcm==. & survey==1976

replace havemarrpreconceptdate = marrpreconceptdate~=. if survey==1976

*In 1973, just use the difference between date1st conception and date 1st marriage

#delimit ;

replace marrpreconceptdate = date1conceptcm-mardate1973>=0 if survey==1973;

replace marrpreconceptdate = . if date1conceptcm==. & survey==1973;

replace marrpreconceptdate = 0 if nevermarried==1;

replace havemarrpreconceptdate = marrpreconceptdate~=. if survey==1973;

gen marrpreconceptdateUSE = marrpreconceptdate;
replace marrpreconceptdateUSE = 0 if havemarrpreconceptdate==0;

gen birthmarrpreconceptdate = firstpregbirthdk*marrpreconceptdateUSE;

tostring date1concept, gen(date1conceptstr) force;
gen year1conceptstr = substr(date1conceptstr,1,4);
destring year1conceptstr, gen(year1concept);

#delimit cr

gen monthsbetwmarrconcept = .
replace monthsbetwmarrconcept = FMAR1CON if (survey==1982|survey==1988)
replace monthsbetwmarrconcept = . if FMAR1CON==999 & survey==1982
replace monthsbetwmarrconcept = -CON1FMAR if (survey==1982|survey==1988) & FMAR1CON==995
replace monthsbetwmarrconcept = . if CON1FMAR==999 & survey==1982 & FMAR1CON==995

replace monthsbetwmarrconcept = MAR1CON1 if survey==1995
replace monthsbetwmarrconcept = -CON1MAR1 if survey==1995 & MAR1CON1==995

replace monthsbetwmarrconcept = date1conceptcm-MARIDT if survey==1976
replace monthsbetwmarrconcept = date1conceptcm-mardate1973 if survey==1973

*Generate shot-gun marriages
gen shotgunnew = 1 if marrpreconceptdateUSE==0 & havemarrpreconceptdate==1 & marrpreoutcome==1
replace shotgunnew = 0 if marrpreconceptdateUSE==1
replace shotgunnew = 0 if marrpreconceptdateUSE==0 & havemarrpreconceptdate==1 & marrpreoutcome==0
replace shotgunnew = . if (havemarrpreconceptdate==0|marrpreoutcome==.)

gen shotgundate1960 = shotgunnew*(date1concept-1960)

*Generate a variable denoting whether the child was adopted
gen adopted = . 

*Note that define adopted using where the child is living now in each of the surveys
*except in 1973 because adoptive parents is not an option--so in 1973 use instead whether
*child ever lived with the mother. This variable is not available in other surveys.

replace adopted = LB1_DTLSTLIV==0 if survey==1973
replace adopted = . if LB1_DTLSTLIV==. & survey==1973

replace adopted = B9_1==7 if survey==1976 & pregnum==1
replace adopted = . if (B9_1==98|B9_1==99) & survey==1976 & pregnum==1

replace adopted = LIV1CHLD==5 if survey==1982 & pregnum==1
replace adopted = . if (LIV1CHLD==9|LIV1CHLD==.) & survey==1982 & pregnum==1

replace adopted = LIV1CHILD==5 if survey==1988 & pregnum==1
replace adopted = . if (LIV1CHILD==.) & survey==1988 & pregnum==1

replace adopted = LIV1CHLD==3 if survey==1995
replace adopted = . if LIV1CHLD==. & survey==1995

#delimit ;
gen infirstmarr = numbermarriages==1 & married==1;
replace infirstmarr = . if (numbermarriages ==.|married==.|nevermarried==1|nevermarried==.) ;

gen marrafterfirst = 1 if numbermarriages>=2;
replace marrafterfirst = 0 if numbermarriages==1 & married==0;
replace marrafterfirst = . if (numbermarriages==.|married==.);

#delimit cr

*Generate the centered version of educpredict2
gen educpredict2resc = educpredict2-12

gen birthdate1960 = firstpregbirthdk*(date1concept-1960)
gen birthdate1960educpred = birthdate1960*educpredict2resc
gen educpreddate1960 = educpredict2resc*(date1concept-1960)

gen birthdate1960marrpreconcept = birthdate1960*marrpreconceptdateUSE
gen date1960marrpreconcept = (date1concept-1960)*marrpreconceptdateUSE

*gen widowed
gen widow = FMARITAL==3
replace widow = MAR_STAT==3 if survey==1973
*Note that in 1976 don't separate widowed and divorced

*Generate number of children variable
gen numchildren = PARITY
replace numchildren = PREG_NUMLIVEB1 if survey==1973
replace numchildren = PREG_LIVEMB if survey==1973 & PREG_LIVEMB~=.
replace numchildren = CEBTOTAL if survey==1976

*Generate income relative to poverty level
gen increlpoverty = FAM_POVERTY if survey==1973
replace increlpoverty = POVERTY if survey>=1974
replace increlpoverty = . if POVERTY==999 & survey==1976

#delimit cr

gen birthdkeducpredict2resc = firstpregbirthdk*educpredict2resc

*Now just count the number of abortions
count if abort==1 & teenpregearlypd==. & pregnum==1
tab date1concept if abort==1 & teenpregearlypd==. & pregnum==1 
tab date1concept if abort==1 & teenpregearlypd==. & pregnum==1 [aw=wtuse]

gen birthprededmarrpreconceptdate = birthdkeducpredict2resc*marrpreconceptdateUSE
gen prededmarrpreconceptdate = educpredict2resc*marrpreconceptdateUSE

save, replace
